package IO流.对象流.ObjectOutputStream.Test02;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

public class ObjectOutputStreamTest02 {
    public static void main(String[] args) {
        List<User> userList = new ArrayList();
        userList.add(new User(10,"李四"));
        userList.add(new User(20,"法外狂徒张三"));
        userList.add(new User(120,"Dio"));
        ObjectOutputStream oos = null;
        try {
            oos = new ObjectOutputStream(new FileOutputStream("D:\\Desktop\\IDEA\\javase\\src\\IO流\\对象流\\ObjectOutputStream\\Test02\\users"));
            oos.writeObject(userList);



            oos.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            if (oos != null) {
                try {
                    oos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
